<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('租后回访') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('回访方式')" prop="returnVisitMethod">
        <el-select v-model="queryParams.returnVisitMethod" :placeholder="$t('回访方式')" clearable>
          <el-option
            v-for="dict in returnVisitMethodOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('回访人员')" prop="returningVisitors">
        <el-input
          v-model="queryParams.returningVisitors"
          :placeholder="$t('回访人员')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('回访日期')" prop="returnVisitDate">
        <el-date-picker
          v-model="dateRange"
          style="width: 400px"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:leaseVisit:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          v-hasPermi="['deal:leaseVisit:export']"-->
      <!--          type="warning"-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="exportHandle"-->
      <!--        >{{ $t('导出') }}</el-button>-->
      <!--      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="dealLeaseVisitList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip min-width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column v-if="!this.$route.query.id" align="center" prop="dealName" :label="$t('项目名称')" show-overflow-tooltip min-width="180">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/deal/home/dealBaseHome',query:{id:scope.row.dealId,companyId:scope.row.companyId}}"
            class="link_a"
          >{{ scope.row.dealName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column v-if="!this.$route.query.id" align="center" prop="renterName" :label="$t('承租人名称')" show-overflow-tooltip min-width="180">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/company/base/companyBaseHome',query:{companyId:scope.row.companyId}}"
            class="link_a"
          >{{ scope.row.companyName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('回访方式')" align="center" prop="returnVisitMethod" :formatter="returnVisitMethodFormat" min-width="180" />
      <el-table-column :label="$t('回访日期')" align="center" prop="returnVisitDate" min-width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.returnVisitDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('回访人员')" align="center" prop="returningVisitors" min-width="180" />
      <el-table-column :label="$t('原资产类别')" align="center" prop="originalAssetClass" :formatter="originalAssetClassFormat" min-width="180" />
      <el-table-column :label="$t('检验后类别')" align="center" prop="afterInspectionCategory" :formatter="afterInspectionCategoryFormat" min-width="180" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" min-width="180" fixed="right">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['deal:leaseVisit:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['deal:leaseVisit:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改租后回访对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealLeaseVisitForm ref="dealLeaseVisitForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealLeaseVisit, delDealLeaseVisit, exportDealLeaseVisit } from '@/api/deal/leasingProject/dealLeaseVisit'
import dealLeaseVisitForm from './dealLeaseVisitForm.vue'
export default {
    components: {
        dealLeaseVisitForm
    },
  data() {
      return {
          dateRange: [],
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 租后回访表格数据
          dealLeaseVisitList: [],
          // 弹出层标题
          title: '租后回访',
          // 是否显示弹出层
          formOpen: false,
        // 回访方式字典
        returnVisitMethodOptions: [],

        // 原资产类别字典
        originalAssetClassOptions: [],

        // 检验后类别字典
        afterInspectionCategoryOptions: [],

          // 查询参数
          queryParams: {
              dealId: this.$route.query.id,
              returnVisitMethod: undefined,
              returnVisitDate: undefined,
              returningVisitors: undefined,
              beginTime: undefined,
              endTime: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      this.getDicts('return_visit_method').then(response => {
          this.returnVisitMethodOptions = response.data
      })
      this.getDicts('original_asset_class').then(response => {
          this.originalAssetClassOptions = response.data
      })
      this.getDicts('original_asset_class').then(response => {
          this.afterInspectionCategoryOptions = response.data
      })
  },
  methods: {
    /** 查询租后回访列表 */
    getList() {
        this.loading = true
      if (this.dateRange != null && this.dateRange.length > 1) {
        this.queryParams.beginTime = this.parseTime(this.dateRange[0])
        this.queryParams.endTime = this.parseTime(this.dateRange[1])
      } else {
        this.queryParams.startDate = undefined
        this.queryParams.endDate = undefined
      }
        listDealLeaseVisit(this.queryParams).then(response => {
            this.dealLeaseVisitList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },
    // 回访方式字典翻译
    returnVisitMethodFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.returnVisitMethodOptions, row.returnVisitMethod)
    },
    // 原资产类别字典翻译
    originalAssetClassFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.originalAssetClassOptions, row.originalAssetClass)
    },
    // 检验后类别字典翻译
    afterInspectionCategoryFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.afterInspectionCategoryOptions, row.afterInspectionCategory)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: undefined,
            dealName: undefined,
            renterName: undefined,
            returnVisitMethod: undefined,
            returnVisitDate: undefined,
            returningVisitors: undefined,
            originalAssetClass: undefined,
            afterInspectionCategory: undefined,
            rentalRecoverySituation: undefined,
            propertyAndProfitability: undefined,
            capabilityAnalysis: undefined,
            solvencyAnalysis: undefined,
            otherReturnVisits: undefined,
            delFlag: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.queryParams.beginTime = undefined
      this.queryParams.endTime = undefined
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.dealLeaseVisitForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealLeaseVisitForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delDealLeaseVisit(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
            this.loading = false
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return exportDealLeaseVisit(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(() => {
        })
    }
  }
}
</script>
